<?php
/*
 * Bootstrap file for initialising the whole application on request.
 * Code courtesy of Akrabat.com
 * Rob Allen
 * Some parts have been modified for interal usage
 */

// Debuggin' Information
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 1);

date_default_timezone_set('Europe/London');

// directory setup and class loading
set_include_path('.' . PATH_SEPARATOR . '../library/'
. PATH_SEPARATOR . '../application/models'
. PATH_SEPARATOR . '../application'
. PATH_SEPARATOR . get_include_path());

// Abrakadabra !!!
include "Zend/Loader.php";
Zend_Loader::registerAutoload(); //Autoload classes Automatically using magic methods

// Load the site configuration
$config = new Zend_Config_Ini('../application/config.ini');

/*
 * Initialise a registry instance for storing the configuration to allow
 * access throughout the whole life of the application
 */

$registry = Zend_Registry::getInstance();
$registry->set('config', $config); //Store the configuration in registry.


//setup the Database Adapter for use in models and other database related calls
$db = Zend_Db::factory($config->general->db);
Zend_Db_Table::setDefaultAdapter($db);

$locale = new Zend_Locale($config->ebay->api->locale);
$registry->set('Zend_Locale', $locale);

$registry->set('db', $db);

//Prepare the EbayClient by passing the config file through a static proceedure

// setup controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory('../application/controllers');


// Setup the routes for the the requests to be mapped to
$router = $frontController->getRouter();
$router->removeDefaultRoutes();


$router->addRoute('index', new Zend_Controller_Router_Route(':action', array('module' => 'default', 'controller' => 'index', 'action' => 'index' )));
$router->addRoute('ajax', new Zend_Controller_Router_Route('ajax/:action/:arg1/:arg2', array('module' => 'default', 'controller' => 'ajax', 'action' => 'index', 'arg1' => null, 'arg2' => null)));
$frontController->setRouter($router);
Zend_Layout::startMvc(array('layoutPath' => '../application/views/layouts'));

// run!
$frontController->dispatch();

